package com.specialized.pay.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.specialized.common.core.domain.Result;
import com.specialized.pay.domain.Trade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.specialized.common.log.annotation.Log;
import com.specialized.common.log.enums.BusinessType;
import com.specialized.common.security.annotation.RequiresPermissions;
import com.specialized.pay.service.ITradeService;
import com.specialized.common.core.web.controller.BaseController;
import com.specialized.common.core.utils.poi.ExcelUtil;

/**
 * 交易流水Controller
 *
 * @author djh
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/trade")
public class TradeController extends BaseController {
    @Autowired
    private ITradeService tradeService;

/**
 * 查询交易流水列表
 */
@RequiresPermissions("trade:trade:list")
@GetMapping("/list")
    public Result list(Trade trade) {
        startPage();
        List<Trade> list = tradeService.selectTradeList(trade);
        return getDataTable(list);
    }

    /**
     * 导出交易流水列表
     */
    @RequiresPermissions("trade:trade:export")
    @Log(title = "交易流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Trade trade) {
        List<Trade> list = tradeService.selectTradeList(trade);
        ExcelUtil<Trade> util = new ExcelUtil<Trade>(Trade. class);
        util.exportExcel(response, list, "交易流水数据");
    }

    /**
     * 获取交易流水详细信息
     */
    @RequiresPermissions("trade:trade:query")
    @GetMapping(value = "/{tradeId}")
    public Result getInfo(@PathVariable("tradeId") Long tradeId) {
        return success(tradeService.selectTradeByTradeId(tradeId));
    }

    /**
     * 新增交易流水
     */
    @RequiresPermissions("trade:trade:add")
    @Log(title = "交易流水", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Trade trade) {
        return toAjax(tradeService.insertTrade(trade));
    }

    /**
     * 修改交易流水
     */
    @RequiresPermissions("trade:trade:edit")
    @Log(title = "交易流水", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Trade trade) {
        return toAjax(tradeService.updateTrade(trade));
    }

    /**
     * 删除交易流水
     */
    @RequiresPermissions("trade:trade:remove")
    @Log(title = "交易流水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{tradeIds}")
    public Result remove(@PathVariable Long[] tradeIds) {
        return toAjax(tradeService.deleteTradeByTradeIds(tradeIds));
    }
}
